<?php
namespace Index\Controller;
use Think\Controller;
use Think\Verify;
class RegisterController extends Controller {
    public function index(){
        If(IS_POST){
            $username = I('post.user_name');
            $mail = I('post.email','','email');
            $password = md5(I('post.password'));
            $verify = I('post.seccode_verify');
            $vit = new Verify();
            if($vit->check($verify,'')) $this->error('验证码不正确','',1);
            $m = M();
            $a = $m->query("select * from user where user_name = '$username'");
//            var_dump(empty($a));
            if(!empty($a)){
                $this->error('用户名已存在','',1);
            }else {
                if(empty($mail)){
                    $this->error('邮箱格式不正确','',2);
                }else{
                    $sql = "insert into `user` (user_name,user_press,mail) values('{$username}','{$password}','{$mail}')";
                    if($m->execute($sql)){
                        $this->error("注册成功");
                    }
                }

            }

        }else{
            $this->display("index");
        }

    }
    public function CodeAction(){
        $config = array(
            'imageW'=>120,
            'imageH'=>40,
            'fontSize'=>16,
            'length'=>4
        );
        $Verify = new Verify($config);
        $Verify->fontttf = '5.ttf';
        $Verify->entry();
    }
}